#include "navigationmanager.h"

NavigationManager::NavigationManager()
{
    m_currentPosition = -1;
}

void NavigationManager::addItem(QString aFile, int aOffset)
{
    if(m_currentPosition == -1)
    {
        //initialization
        m_fileItems.clear();
        m_offsetItems.clear();
        m_fileItems.append(aFile);
        m_offsetItems.append(aOffset);
        m_currentPosition = 0;
        return;
    }

    if(m_fileItems[m_currentPosition] == aFile && m_offsetItems[m_currentPosition] == aOffset)
        return;//do not duplicate items

    //delete everything after current position
    while(m_fileItems.size() > m_currentPosition + 1)
    {
        m_fileItems.removeLast();
        m_offsetItems.removeLast();
    }

    m_fileItems.append(aFile);
    m_offsetItems.append(aOffset);
    m_currentPosition = m_fileItems.size() - 1;
}

bool NavigationManager::next(QString &aFile, int &aOffset)
{
    if(m_currentPosition == -1)
        return false;
    if(m_currentPosition >= m_fileItems.size() - 1)
        return false;
    m_currentPosition++;
    aFile = m_fileItems[m_currentPosition];
    aOffset = m_offsetItems[m_currentPosition];
    return true;
}


bool NavigationManager::previous(QString &aFile, int &aOffset)
{
    if(m_currentPosition <= 0)
        return false;
    m_currentPosition--;
    aFile = m_fileItems[m_currentPosition];
    aOffset = m_offsetItems[m_currentPosition];
    return true;
}



bool NavigationManager::canGoNext()
{
    return m_currentPosition != -1 && m_currentPosition < m_fileItems.size() - 1;
}

bool NavigationManager::canGoPrevious()
{
    return m_currentPosition > 0;
}


